package thing1;


import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;


/*
*   生产者
*
* */
public class Producer {

    public static void main(String[] args) throws Exception{
        //创建事务生产者
        TransactionMQProducer wx = new TransactionMQProducer("tran_producer");

        //2. 设置NameService地址
        wx.setNamesrvAddr("localhost:9876");

        //指定事务监听器
        wx.setTransactionListener(new MyTranListener());

        //开启生产者
        wx.start();
        //创建消息体
        Message message = new Message("tran", "hello","12", "我在源码学习java".getBytes(StandardCharsets.UTF_8));
        //发送单向消息
        wx.sendMessageInTransaction(message,null);
        //关闭
        wx.shutdown();
    }
    }

